package com.example.capsule_kafka.impl;

import com.example.capsule_kafka.bean.PositionBean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.*;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;


/**
 * @Author: zhuzhiming
 * @Date: 2022/5/18 12:46
 */
@Service
@Slf4j
public class PositionServiceImpl {

    @Autowired
    RedisTemplate<String, String> redisTemplate;

    public void uploadPosition(PositionBean positionBean) {

        String key = positionBean.getField().toLowerCase() + "-Position";
        Point point = new Point(positionBean.getLongitude(), positionBean.getLatitude());
        String userId = positionBean.getUserId();
        redisTemplate.opsForGeo().add(key, point, userId);
        redisTemplate.opsForValue().set(positionBean.getUserId() + "-uploadPositionTime", positionBean.getUploadTime(), 10, TimeUnit.MINUTES);
    }
}
